<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>${product.title} - 校园二手市场</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
    <style>
        /* 基础样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: "Noto Serif SC", "Source Han Serif SC", "SimSun", "Times New Roman", serif;
        }

        body {
            background-color: #f5f5f5;
            color: #333;
            line-height: 1.6;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        a {
            text-decoration: none;
            color: inherit;
        }

        .container {
            width: 90%;
            max-width: 1200px;
            margin: 5px auto;
            padding: 0 15px;
            flex: 1;
        }

        /* 头部样式 */
        .header {
            background-color: #2c3e50;
            color: white;
            padding: 15px 0;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
        }

        .header .container {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .logo h1 {
            font-size: 2.5rem;
            display: flex;
            align-items: center;
            font-weight: 700;
            min-width: 400px;
            letter-spacing: 2px;
            text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
        }

        .logo i.fa-recycle {
            font-size: 2.5rem;
            margin-right: 15px;
            vertical-align: middle;
            color: #e74c3c;
        }

        .user-menu ul {
            display: flex;
            list-style: none;
        }

        .user-menu li {
            margin-left: 20px;
            min-width: 100px;
        }

        .user-menu a {
            display: flex;
            align-items: center;
            font-size: 15px;
            font-weight: 500;
            transition: color 0.3s;
            padding: 8px 0;
        }

        .user-menu a:hover {
            color: #e74c3c;
            transition: color 0.3s;
        }

        .user-menu i {
            margin-right: 8px;
            font-size: 1.1rem;
        }

        /* 返回按钮 */
        .back-button {
            margin: 20px 0;
        }

        .back-button a {
            display: inline-flex;
            align-items: center;
            color: #2c3e50;
            font-weight: 500;
            padding: 8px 15px;
            border-radius: 4px;
            background-color: #f8f9fa;
            transition: all 0.3s;
        }

        .back-button a:hover {
            background-color: #e9ecef;
            text-decoration: none;
        }

        .back-button i {
            margin-right: 8px;
        }

        /* 商品详情容器 */
        .product-detail-container {
            background-color: white;
            padding: 30px;
            margin: 20px auto;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
            max-width: 1000px;
            display: flex;
            flex-wrap: wrap;
        }

        /* 商品图片区域 */
        .product-images {
            flex: 1.2;
            min-width: 350px;
            padding-right: 40px;
        }

        .main-image {
            width: 100%;
            height: 450px;
            background-color: #f8f9fa;
            border-radius: 8px;
            overflow: hidden;
            display: flex;
            padding: 20px;
            align-items: center;
            justify-content: center;
            margin-bottom: 30px;
        }

        .main-image img {
            min-width: 95%;
            min-height: 95%;
            max-width: 100%;
            max-height: 100%;
            object-fit: contain;
        }

        /* 卖家信息区域 */
        .seller-info-box {
            background-color: #f8f9fa;
            border-radius: 8px;
            padding: 15px;
            display: flex;
            align-items: center;
            margin-top: 15px;
        }

        .seller-avatar {
            width: 100px;
            height: 100px;
            border-radius: 50%;
            overflow: hidden;
            margin-right: 15px;
            border: 2px solid #e74c3c;
        }

        .seller-avatar img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .seller-info {
            margin: 5px 0;
            font-size: 14px;
        }

        .seller-name {
            font-weight: bold;
            color: #2c3e50;
            font-size: 25px;
        }

        .seller-phone {
            color: #e74c3c;
            cursor: pointer;
            margin-top: 3px;
        }

        /* 商品信息区域 */
        .product-info {
            flex: 0.8;
            min-width: 300px;
        }

        .product-title {
            font-size: 1.8rem;
            color: #2c3e50;
            margin-bottom: 15px;
            padding-bottom: 15px;
            border-bottom: 1px solid #eee;
        }

        /* 商品信息卡片 */
        .info-card {
            background-color: #f8f9fa;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 25px;
        }

        .info-row {
            display: flex;
            margin-bottom: 12px;
            font-size: 16px;
        }

        .info-label {
            color: #7f8c8d;
            min-width: 90px;
        }

        .info-value {
            color: #333;
            font-weight: 500;
        }

        /* 价格区域 */
        .price-row {
            display: flex;
            align-items: baseline;
            margin-bottom: 15px;
        }

        .current-price {
            font-size: 2rem;
            color: #e74c3c;
            font-weight: bold;
        }

        .original-price {
            font-size: 1.4rem;
            color: #95a5a6;
            text-decoration: line-through;
            margin-left: 10px;
        }

        /* 成色标签样式 */
        .condition-1 {
            color: #28a745;
            font-weight: bold;
        }

        .condition-2 {
            color: #17a2b8;
            font-weight: bold;
        }

        .condition-3 {
            color: #ffc107;
            font-weight: bold;
        }

        .condition-4 {
            color: #fd7e14;
        }

        .condition-5 {
            color: #dc3545;
            font-weight: bold;
        }

        /* 商品描述 */
        .description-card {
            background-color: #f8f9fa;
            border-radius: 8px;
            padding: 20px;
            min-height: 160px;
            margin-bottom: 25px;
        }

        .description-title {
            font-size: 1.3rem;
            color: #2c3e50;
            margin-bottom: 15px;
        }

        .description-content {
            color: #555;
            line-height: 1.8;
            font-size: 15px;
            white-space: pre-line;
        }

        .error-message {
            color: #e74c3c;
            text-align: center;
            margin: 30px 0;
            font-size: 1.1rem;
            padding: 15px;
            background-color: rgba(231, 76, 60, 0.1);
            border-radius: 8px;
            border-left: 5px solid #e74c3c;
        }

        .success-message {
            color: #27ae60;
            text-align: center;
            margin: 30px 0;
            font-size: 1.1rem;
            padding: 15px;
            background-color: rgba(39, 174, 96, 0.1);
            border-radius: 8px;
            border-left: 5px solid #27ae60;
        }

        /* 操作按钮 */
        .action-buttons {
            display: flex;
            gap: 15px;
            margin-top: 20px;
        }

        .btn {
            padding: 14px 20px;
            border-radius: 4px;
            font-size: 16px;
            cursor: pointer;
            transition: all 0.3s;
            text-align: center;
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
        }

        .btn-primary {
            background-color: #e74c3c;
            color: white;
            border: none;
        }

        .btn-primary:hover {
            background-color: #c0392b;
        }

        .btn-outline {
            background-color: transparent;
            border: 1px solid #e74c3c;
            color: #e74c3c;
        }

        .btn-outline:hover {
            background-color: rgba(231, 76, 60, 0.1);
        }

        /* 页脚 */
        .footer {
            background-color: #2c3e50;
            color: #ecf0f1;
            padding: 40px 0 20px;
        }

        .footer-content {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 30px;
            margin-bottom: 30px;
        }

        .footer-section h3 {
            color: white;
            margin-bottom: 15px;
            font-size: 1.2rem;
        }

        .footer-section p {
            margin-bottom: 10px;
        }

        .footer-section ul {
            list-style: none;
        }

        .footer-section li {
            margin-bottom: 8px;
        }

        .footer-section a:hover {
            color: #e74c3c;
        }

        .footer-section i {
            margin-right: 8px;
            width: 20px;
            text-align: center;
        }

        .copyright {
            text-align: center;
            padding-top: 20px;
            border-top: 1px solid #34495e;
            font-size: 0.9rem;
            color: #bdc3c7;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .header .container {
                flex-direction: column;
            }

            .logo h1 {
                font-size: 1.8rem;
                justify-content: center;
                margin-bottom: 10px;
            }

            .user-menu ul {
                width: 100%;
                justify-content: space-around;
            }

            .user-menu li {
                margin-left: 0;
            }

            .product-detail-container {
                flex-direction: column;
            }

            .product-images {
                padding-right: 0;
                margin-bottom: 30px;
            }

            .main-image {
                height: 300px;
            }

            .action-buttons {
                flex-direction: column;
            }
        }
    </style>
</head>
<body>
<!-- 顶部导航栏 -->
<header class="header">
    <div class="container">
        <div class="logo">
            <a href="${pageContext.request.contextPath}/home"><h1><i class="fas fa-recycle"></i> 校园二手市场</h1></a>
        </div>
        <nav class="user-menu">
            <ul>
                <li>
                    <c:if test="${not empty user}">
                        <a href="${pageContext.request.contextPath}/userCenter"><i
                                class="fas fa-user"></i>&nbsp;${user.username}</a>
                    </c:if>
                    <c:if test="${empty user}">
                        <a href="${pageContext.request.contextPath}/login"><i class="fas fa-user"></i> 登录</a>
                    </c:if>
                </li>
                <li>
                    <c:if test="${not empty user}">
                        <a href="${pageContext.request.contextPath}/messages">
                            <i class="fas fa-bell"></i> 消息
                        </a>
                    </c:if>
                    <c:if test="${empty user}">
                        <a href="${pageContext.request.contextPath}/register"><i class="fas fa-user-plus"></i> 注册</a>
                    </c:if>
                </li>
                <li><a href="${pageContext.request.contextPath}/orderCar"><i class="fas fa-shopping-cart"></i> 购物车</a>
                </li>
                <li><a href="${pageContext.request.contextPath}/productCenter"><i class="fas fa-box-open"></i> 我的商品</a>
                </li>
            </ul>
        </nav>
    </div>
</header>

<c:if test="${not empty productErrorInfo}">
    <div class="error-message">${productErrorInfo}</div>
</c:if>

<c:if test="${not empty productSuccessInfo}">
    <div class="success-message">${productSuccessInfo}</div>
</c:if>

<!-- 商品详情内容 -->
<div class="container">
    <!-- 返回按钮 -->
    <div class="back-button">
        <a href="javascript:history.back()"><i class="fas fa-arrow-left"></i> 返回</a>
    </div>

    <div class="product-detail-container">
        <!-- 商品图片区域 -->
        <div class="product-images">
            <div class="main-image">
                <img src="${pageContext.request.contextPath}/productPictures/${product.productId}/${product.imageUrl}"
                     onerror="this.src='${pageContext.request.contextPath}/default-product.webp'"
                     alt="${product.title}">
            </div>

            <!-- 卖家信息区域 -->
            <div class="seller-info-box">
                <div class="seller-avatar">
                    <img src="${pageContext.request.contextPath}/userPictures/${product.userId}/${userUtils.getUserAvatar(product.userId)}"
                         onerror="this.src='${pageContext.request.contextPath}/default-avatar.jpg'" alt="卖家头像">
                </div>
                <div>
                    <div class="seller-info">
                        <div class="seller-name">
                            卖家：${userUtils.getRealName(product.userId)}
                            <div class="seller-phone">
                                📞: ${productUtils.getProductSellerPhone(product.productId)}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 商品信息区域 -->
        <div class="product-info">
            <h1 class="product-title">${product.title}</h1>

            <!-- 商品基本信息卡片 -->
            <div class="info-card">
                <div class="info-row">
                    <span class="info-label">商品分类</span>
                    <span class="info-value">
                        <c:choose>
                            <c:when test="${product.categoryId == 1}">教材书籍</c:when>
                            <c:when test="${product.categoryId == 2}">电子产品</c:when>
                            <c:when test="${product.categoryId == 3}">服装鞋帽</c:when>
                            <c:when test="${product.categoryId == 4}">交通工具</c:when>
                            <c:when test="${product.categoryId == 5}">生活用品</c:when>
                            <c:when test="${product.categoryId == 6}">文体娱乐</c:when>
                            <c:when test="${product.categoryId == 7}">其他商品</c:when>
                        </c:choose>
                    </span>
                </div>
                <div class="info-row">
                    <span class="info-label">商品成色</span>
                    <span class="info-value condition-${product.conditionLevel}">
                        <c:choose>
                            <c:when test="${product.conditionLevel == 1}">全新</c:when>
                            <c:when test="${product.conditionLevel == 2}">几乎全新</c:when>
                            <c:when test="${product.conditionLevel == 3}">轻微使用痕迹</c:when>
                            <c:when test="${product.conditionLevel == 4}">明显使用痕迹</c:when>
                            <c:when test="${product.conditionLevel == 5}">需要维修</c:when>
                        </c:choose>
                    </span>
                </div>
                <div class="info-row">
                    <span class="info-label">发布时间</span>
                    <span class="info-value"><fmt:formatDate value="${product.createTime}"
                                                             pattern="yyyy-MM-dd HH:mm"/></span>
                </div>
                <div class="info-row">
                    <span class="info-label">商品状态</span>
                    <span class="info-value">
                        <c:choose>
                            <c:when test="${product.status == 1}"><span style="color: #28a745;">在售中</span></c:when>
                            <c:when test="${product.status == -1}"><span style="color: #6c757d;">已售出</span></c:when>
                        </c:choose>
                    </span>
                </div>

                <!-- 价格区域 -->
                <div class="price-row">
                    <span class="current-price">¥<fmt:formatNumber value="${product.price}" pattern="0.00"/></span>
                    <c:if test="${product.originalPrice > 0}">
                        <span class="original-price">¥<fmt:formatNumber value="${product.originalPrice}"
                                                                        pattern="0.00"/></span>
                    </c:if>
                </div>
            </div>

            <!-- 商品描述卡片 -->
            <div class="description-card">
                <h3 class="description-title">商品描述</h3>
                <div class="description-content">${product.description}</div>
            </div>

            <!-- 操作按钮 -->
            <div class="action-buttons">
                <c:choose>
                    <c:when test="${product.status == 1}">
                        <c:if test="${user.userId != product.userId}">
                            <button class="btn btn-primary"
                                    onclick="window.location.href='${pageContext.request.contextPath}/addCarItem?productId=${product.productId}'">
                                <i class="fas fa-cart-plus"></i> 加入购物车
                            </button>
                            <button class="btn btn-outline"
                                    onclick="window.location.href='${pageContext.request.contextPath}/confirmOrder?productId=${product.productId}'">
                                <i class="fas fa-shopping-bag"></i> 立即购买
                            </button>
                        </c:if>
                        <c:if test="${user.userId == product.userId}">
                            <a href="${pageContext.request.contextPath}/productUpdate?productId=${product.productId}"
                               class="btn btn-outline">
                                <i class="fas fa-edit"></i> 编辑商品
                            </a>
                            <button class="btn btn-outline" onclick="if(confirm('确定要下架此商品吗？')) {
                                    window.location.href='${pageContext.request.contextPath}/productRemove?productId=${product.productId}'
                                    }">
                                <i class="fas fa-trash-alt"></i> 下架商品
                            </button>
                        </c:if>
                    </c:when>
                    <c:when test="${product.status == -1}">
                        <button class="btn btn-outline" disabled>
                            商品已售出
                        </button>
                    </c:when>
                    <c:when test="${product.status == 0}">
                        <button class="btn" disabled>
                            商品已下架
                        </button>
                        <c:if test="${user.userId == product.userId}">
                            <button class="btn btn-outline" onclick="if(confirm('确定要重新上架此商品吗？')) {
                                    window.location.href='${pageContext.request.contextPath}/productRestore?productId=${product.productId}'
                                    }">
                                <i class="fas fa-store"></i> 上架商品
                            </button>
                        </c:if>
                    </c:when>
                </c:choose>
            </div>
        </div>
    </div>
</div>

<!-- 页脚 -->
<footer class="footer">
    <div class="container">
        <div class="footer-content">
            <div class="footer-section">
                <h3>关于我们</h3>
                <p>校园二手市场致力于为同学们提供安全、便捷的二手交易平台，促进资源循环利用。</p>
            </div>
            <div class="footer-section">
                <h3>快速链接</h3>
                <ul>
                    <li><a href="${pageContext.request.contextPath}/home">首页</a></li>
                    <li><a href="${pageContext.request.contextPath}/productUpload">发布商品</a></li>
                    <li><a href="${pageContext.request.contextPath}/showAllOrder">我的订单</a></li>
                </ul>
            </div>
            <div class="footer-section">
                <h3>联系我们</h3>
                <p><i class="fas fa-envelope"></i> 2424717883@qq.com</p>
                <p><i class="fas fa-phone"></i> 17868292884</p>
            </div>
        </div>
        <div class="copyright">
            <p>&copy; 2025 CB 校园二手市场 版权所有</p>
        </div>
    </div>
</footer>

</body>
</html>